package listbyorder.access001_100.test44;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/19 10:44
 */
public class Solution3 {

    // 动态规划——正向遍历
    public boolean isMatch(String s, String p) {
        if (p.equals("")) return s.equals("");
        int cs = s.length();
        int cp = p.length();
        boolean[][] dp = new boolean[cs + 1][cp + 1];
        for (int i = 0; i <= cs; i++) {
            for (int j = 0; j <= cp; j++) {
                if (i == 0 && j == 0) {
                    dp[i][j] = true;
                } else if (i == 0) {
                    dp[i][j] = p.charAt(j - 1) == '*' && dp[i][j - 1];
                } else if (j == 0) {
                } else if (s.charAt(i - 1) == p.charAt(j - 1) || p.charAt(j - 1) == '?') {
                    dp[i][j] = dp[i - 1][j - 1];
                } else if (p.charAt(j - 1) == '*') {
                    dp[i][j] = dp[i - 1][j] || dp[i][j - 1] || dp[i - 1][j - 1];
                }
            }
        }
        return dp[cs][cp];
    }
}
